#region Using directives
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using webapp4U.BOL;
#endregion


namespace webapp4U.DAL
{
	 public class SlideShowDAL : BaseDAL
	 {
         #region ObjIDataReader

         /// <summary>
         /// Returns a new SlideShow instance filled with the DataReader's current record data 
         /// </summary>
         private SlideShow GetSlideShowFromReader(IDataReader dr)
         {
             SlideShow obj = new SlideShow();
             obj.SlideShowID = (dr["SlideShowID"] is DBNull) ? Int32.MinValue : (Int32)dr["SlideShowID"];
             obj.AddedDate = (dr["AddedDate"] is DBNull) ? DateTime.MinValue : (DateTime)dr["AddedDate"];
             obj.BosuutapID = (dr["BosuutapID"] is DBNull) ? Int32.MinValue : (Int32)dr["BosuutapID"];
             obj.Title = (dr["Title"] is DBNull) ? String.Empty : (String)dr["Title"];
             obj.ImageUrl = (dr["ImageUrl"] is DBNull) ? String.Empty : (String)dr["ImageUrl"];
             obj.Description = (dr["Description"] is DBNull) ? String.Empty : (String)dr["Description"];
             obj.IsActive = (dr["IsActive"] is DBNull) ? false : (Boolean)dr["IsActive"];
             obj.DisplayOrder = (dr["DisplayOrder"] is DBNull) ? Int32.MinValue : (Int32)dr["DisplayOrder"];
             return obj;
         }
         #endregion

         /// <summary>
         /// Returns a collection of SlideShow with the data read from the input DataReader
         /// </summary>
         private List<SlideShow> GetSlideShowCollectionFromReader(IDataReader dr)
         {
             List<SlideShow> obj = new List<SlideShow>();
             while (dr.Read())
                 obj.Add(GetSlideShowFromReader(dr));
             return obj;
         }

         public int Insert(SlideShow obj)
         {
             using (SqlConnection myConn = GetConnectionString())
             {
                 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_Insert", myConn);
                 myCommand.CommandType = CommandType.StoredProcedure;
                 myCommand.Parameters.Add("@SlideShowID", SqlDbType.Int).Direction = ParameterDirection.Output;
                 myCommand.Parameters.Add("@AddedDate", SqlDbType.DateTime).Value = obj.AddedDate;
                 myCommand.Parameters.Add("@BosuutapID", SqlDbType.Int).Value = obj.BosuutapID;
                 myCommand.Parameters.Add("@Title", SqlDbType.NVarChar).Value = obj.Title;
                 myCommand.Parameters.Add("@ImageUrl", SqlDbType.NVarChar).Value = obj.ImageUrl;
                 myCommand.Parameters.Add("@Description", SqlDbType.NVarChar).Value = obj.Description;
                 myCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value = obj.IsActive;
                 myCommand.Parameters.Add("@DisplayOrder", SqlDbType.Int).Value = obj.DisplayOrder;

                 int ret = myCommand.ExecuteNonQuery();
                 return (int)myCommand.Parameters["@SlideShowID"].Value;
             }
         }

         public bool Update(SlideShow obj)
         {
             using (SqlConnection myConn = GetConnectionString())
             {
                 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_Update", myConn);
                 myCommand.CommandType = CommandType.StoredProcedure;
                 myCommand.Parameters.Add("@SlideShowID", SqlDbType.Int).Value = obj.SlideShowID;
                 myCommand.Parameters.Add("@AddedDate", SqlDbType.DateTime).Value = obj.AddedDate;
                 myCommand.Parameters.Add("@BosuutapID", SqlDbType.Int).Value = obj.BosuutapID;
                 myCommand.Parameters.Add("@Title", SqlDbType.NVarChar).Value = obj.Title;
                 myCommand.Parameters.Add("@ImageUrl", SqlDbType.NVarChar).Value = obj.ImageUrl;
                 myCommand.Parameters.Add("@Description", SqlDbType.NVarChar).Value = obj.Description;
                 myCommand.Parameters.Add("@IsActive", SqlDbType.Bit).Value = obj.IsActive;
                 myCommand.Parameters.Add("@DisplayOrder", SqlDbType.Int).Value = obj.DisplayOrder;

                 int ret = myCommand.ExecuteNonQuery();
                 return (ret == 1);
             }
         }


	 public bool Delete(Int32 SlideShowID)
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_Delete", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 myCommand.Parameters.Add("@SlideShowID", SqlDbType.Int).Value = SlideShowID;

		 int ret = myCommand.ExecuteNonQuery();
		 return (ret == 1);
		 }
	 }

	 /// <summary>
	 /// Retrieves the w4u_SlideShow with the specified ID
	 /// </summary>
	 public SlideShow GetSlideShowByID(Int32 SlideShowID)
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_GetSlideShowByID", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 myCommand.Parameters.Add("@SlideShowID", SqlDbType.Int).Value = SlideShowID;

		 SqlDataReader dr = myCommand.ExecuteReader();
		 return (dr.Read() ? GetSlideShowFromReader(dr) : null);
		 }
	 }

	 //Get All SlideShow
	 public List<SlideShow> GetAllSlideShow(int PageIndex, int PageSize)
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_GetAllSlideShow", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 myCommand.Parameters.Add("@PageIndex", SqlDbType.Int).Value = PageIndex;
		 myCommand.Parameters.Add("@PageSize", SqlDbType.Int).Value = PageSize;
		 SqlDataReader dr = myCommand.ExecuteReader();
		 return GetSlideShowCollectionFromReader(dr);
		 }
	 }

	 // Get Count All records of Table  SlideShow
	 public int GetCountSlideShow()
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_GetCountSlideShow", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 return (int)myCommand.ExecuteScalar();
		 }
	 }

	 // Get SlideShowByBosuutapID
	 public List<SlideShow> GetSlideShowByBosuutapID(Int32 BosuutapID,int PageIndex, int PageSize)
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_GetSlideShowByBosuutapID", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 myCommand.Parameters.Add("@BosuutapID", SqlDbType.Int).Value = BosuutapID;
		 myCommand.Parameters.Add("@PageIndex", SqlDbType.Int).Value = PageIndex;
		 myCommand.Parameters.Add("@PageSize", SqlDbType.Int).Value = PageSize;
		 SqlDataReader dr = myCommand.ExecuteReader();
		 return GetSlideShowCollectionFromReader(dr);
		 }
	 }

	 // Get SlideShowCountByBosuutapID
	 public int GetSlideShowCountByBosuutapID(Int32 BosuutapID)
	 {
		 using (SqlConnection myConn = GetConnectionString())
		 {
		 SqlCommand myCommand = new SqlCommand("w4u_SlideShow_GetSlideShowCountByBosuutapID", myConn); 
		 myCommand.CommandType = CommandType.StoredProcedure; 
		 myCommand.Parameters.Add("@BosuutapID", SqlDbType.Int).Value = BosuutapID;
		 return (int)myCommand.ExecuteScalar();
		 }
	 }

	 }
}
